import dayjs from 'dayjs';
import mongoose, { Schema } from 'mongoose';

export interface IAdmin {
	_id: string;
	avatar: string;
	nickname: string;
	username: string;
	password: string;
	createdAt: string;
	updatedAt: string;
}

const AdminSchema = new Schema<IAdmin>(
	{
		avatar: { type: String },
		nickname: { type: String, required: true },
		username: { type: String, required: true, unique: true },
		password: { type: String, required: true },
		createdAt: {
			type: String,
			default: () => dayjs().format('YYYY年MM月DD日 HH:mm:ss'),
		},
		updatedAt: {
			type: String,
			default: () => dayjs().format('YYYY年MM月DD日 HH:mm:ss'),
		},
	},
	{
		collection: 'admin',
	}
);

export const AdminModel = mongoose.model<IAdmin>('Admin', AdminSchema);
